//
//  LoginRequestLogic.m
//  AAIM
//
//  Created by awh on 2019/12/2.
//  Copyright © 2019年 AAIM. All rights reserved.
//

#import "LoginRequestLogic.h"
//注册
#define UserRegisterURL @"/login/registered"
//账号密码登陆
#define UserLogin @"/login/loginPwd"
//验证码登录
#define UserCodeLogin @"/login/loginV"
//获取验证码
#define GetLoginCode @"/login/sendCode"
//获取配置信息
#define GetAppInfo @"/common/configuration"
//上传文件
#define UpLoad @"/upload"
//临时token
#define TempToken @"/common/token"


@implementation LoginRequestLogic

+(void)getAppInfoUrlwithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(NSString * _Nonnull))failure{
    [[NetWorkTool shareInstance] getAppInfoPath:GetAppInfo method:HttpRequestPost completion:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        success(responseObject);
//        NSLog(@"配置信息：%@",responseObject);
    }];
}

+(void)getTempTokenSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(NSString * _Nonnull))failure{

    [[NetWorkTool shareInstance] requestTempTokenWithPath:TempToken method:HttpRequestPost completion:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        success(responseObject);
        if ([responseObject[@"code"] integerValue] == 200) {
            [[NSUserDefaults standardUserDefaults] setObject:responseObject[@"data"][@"lsToken"] forKey:@"TemToken"];
            [[NSUserDefaults standardUserDefaults]synchronize];
        }
    }];
}

+(void)UserRigisterWithHead:(NSString*)head  nickname:(NSString*)nickname password:(NSString*)password sex:(NSString*)sex username:(NSString*)username invitationCode:(NSString*)invitationCode userUUid:(NSString*)uuid Success:(void (^)(NSDictionary *Dict))success failure:(void (^)(NSString* errMsg))failure
{
    NSMutableDictionary * paramentdic =[[NSMutableDictionary alloc]init];
    if (head) {
       [paramentdic setValue:head forKey:@"head"];
    }
    
    [paramentdic setValue:nickname forKey:@"nickname"];
    [paramentdic setValue:password forKey:@"password"];
    [paramentdic setValue:sex forKey:@"sex"];
    [paramentdic setValue:username forKey:@"username"];
    [paramentdic setValue:invitationCode forKey:@"invitationCode"];
    [paramentdic setValue:uuid forKey:@"uuid"];
    [paramentdic setValue:uuid forKey:@"udid"];
    
    [[NetWorkTool shareInstance]requestWithPath:UserRegisterURL method:HttpRequestPost paramenters:paramentdic completion:^(SLResultModel * _Nonnull res) {

        if (res.isSuccess) {

            success(res.rawdata);

        }else
        {
            if (res.message) {
                failure(res.message);
            }else{
                failure(res.msg);
            }
        }

    }];

}

+(void)UserLoginUserName:(NSString *)UserName withType:(NSInteger)type withPassword:(nonnull NSString *)password userUUid:(nonnull NSString *)uuid invitationCode:(nonnull NSString *)invitationCode Success:(nonnull void (^)(NSDictionary * _Nonnull))success failure:(nonnull void (^)(NSString * _Nonnull))failure{
  
    NSMutableDictionary * paramentdic =[[NSMutableDictionary alloc]init];

    if (type == 1) {
        [paramentdic setValue:password forKey:@"password"];
        [paramentdic setValue:UserName forKey:@"username"];
        [paramentdic setValue:uuid forKey:@"udid"];
        [paramentdic setValue:uuid forKey:@"uuid"];

        [[NetWorkTool shareInstance]requestWithPath:UserLogin method:HttpRequestPost paramenters:paramentdic completion:^(SLResultModel * _Nonnull res) {
            if (res.isSuccess) {
                success(res.rawdata);
            }else
            {
                failure(res.message);
            }
            
        }];
    }else{
        [paramentdic setValue:password forKey:@"tvcode"];
        [paramentdic setValue:UserName forKey:@"tel"];
        [paramentdic setValue:uuid forKey:@"udid"];
        [paramentdic setValue:invitationCode forKey:@"inviteCode"];
        
        [[NetWorkTool shareInstance]requestWithPath:UserCodeLogin method:HttpRequestPost paramenters:paramentdic completion:^(SLResultModel * _Nonnull res) {
        if (res.isSuccess) {
            success(res.rawdata);
        }else
         {
             failure(res.message);
         }
        }];
    }

    
}

//获取验证码
+ (void)UserLoginCode:(NSString *)code withType:(NSString *)type Success:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(NSString * _Nonnull))failure{
    
    NSMutableDictionary * paramentdic = [[NSMutableDictionary alloc]init];
    [paramentdic setValue:code forKey:@"tel"];
    [paramentdic setValue:type forKey:@"type"];
    [[NetWorkTool shareInstance]requestWithPath:GetLoginCode method:HttpRequestGet paramenters:paramentdic completion:^(SLResultModel * _Nonnull res) {
        if (res.isSuccess) {
           success(res.rawdata);
        }else
        {
            failure(res.msg);
        }
    }];
    
}


//上传文件
+(void)upLoadFile:(UIImage *)image withToken:(nonnull NSString *)token Success:(nonnull void (^)(NSDictionary * _Nonnull))success failure:(nonnull void (^)(NSString * _Nonnull))failure{

    [[NetWorkTool shareInstance] uploadImage:image withURL:UpLoad withToken:token completion:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        if ([responseObject[@"code"] integerValue] == 200) {
            success(responseObject);
        }else{
            failure(responseObject);
        }
    }];
    

    
}

+ (void)upLoadReportPictureFile:(UIImage *)image withToken:(NSString *)token withType:(NSString *)type Success:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(NSString * _Nonnull))failure{
    [[NetWorkTool shareInstance]uploadMoreImage:image withURL:UpLoad withToken:token withType:type completion:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        if ([responseObject[@"code"] integerValue] == 200) {
            success(responseObject);
        }else{
            failure(responseObject);
        }
    }];
    
}


@end
